<template>
    <div id="member">
        <el-col :span="24" class="action-bar">
                <el-button type="primary" size="medium" @click="adminVisible=true">添加</el-button>
            </el-col>
        

        <!-- 列表 -->
        <el-table
            :data="tableData"
            style="width: 100%">
            <el-table-column
                prop="phone"
                label="名称"
                width="200"
                >
            </el-table-column>
            <el-table-column
                prop="phone"
                label="手机号"
                width="200"
                >
            </el-table-column>
            <el-table-column
                prop="address"
                label="创建时间"
                width="200"
                >
            </el-table-column>
            
            <el-table-column label="操作" width='143'>
                <template slot-scope="scope">
                    <el-button type='text' @click="deleteCircle(scope.row.id)" >删除</el-button>
                </template>
            </el-table-column>
            
        </el-table>

		        <el-dialog :visible.sync="adminVisible" @close="initData" title="设置管理员" width="30vw">
            <el-form>
                <el-form-item label="添加管理员" label-width="100px">
                    <el-select
                        v-model="executor"
                        filterable
                        remote
                        :loading="loading"
                        placeholder="请输入会员名"
                        @change="getExecutor"
                        :remote-method="searchName"
                        size="medium"
                            >
                        <div v-if="vipList.length!=0">
                            <el-option
                            v-for="(item) in vipList"
                            :key="item.id"
                            :label="item.realname?item.nickname:item.nickname"
                            :value="item.user_id">
                        </el-option>
                        </div>
                    </el-select>
                </el-form-item>
                <el-form-item label="角色" label-width="100px">
                    <el-select
                        v-model="role"
                        size="medium"
                            >
                        <div v-if="roleList.length!=0">
                            <el-option
                            v-for="(item) in roleList"
                            :key="item.id"
                            :label="item.display_name"
                            :value="item.id">
                        </el-option>
                        </div>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="setCircleAdmin">提交</el-button>
			</div>
        </el-dialog>
    </div>
</template>
<script>
export default {
    name:'member',
    data() {
        return {
            id:'',//圈子id
            vipList:[],
            executor:'',
            loading:false,
            name:'',
            circleTypeId:'',//选中的用户id
            tableData: [{}],
            page:1,
            totalPage:0,
            adminVisible:false,//设置管理员弹窗    
            role:'',
            roleList:[],//角色列
        }
    },
    methods: { 
        async setCircleAdmin(){
            //设置为圈主
            let params={
                user_id:this.executor,
                circle_id:this.id,
                role_id:this.role
            }
            let res=await this.$api.setCircleAdmin(params);
            if(res.data.level=='success'){
                this.$message({
                    type:'success',
                    message:res.data.message
                })
                this.adminVisible=false;
            }else{
                this.$message({
                    type:'error',
                    message:res.data.message
                })
            }
              
        },
        getExecutor(e){
            this.executor=e;
            console.log(this.executor)
		    },
		async searchName(searchText){
			//搜索用户名
			this.loading=true;
            let params={
                page:1,
                limit:999,
                keyword: searchText
            }
            let res=await this.$api.getUserList(params);
			if(res.data.level=='success'){
                let arr=[]
                res.data.data.forEach(item=>{
                    if(item.user_info){
                        arr.push(item.user_info) 
                    }
                });
                this.vipList=arr
                console.log(this.vipList,55555)
			}
			this.loading=false
    	},     
        async getCircleAdminList(){
            let params={
                page:this.page,
                circle_id:this.id,
                limit:16,
            }
            let res=await this.$api.getCircleAdminList(
                params);
            if(res.data.level=='success'){
                this.tableData=res.data.data;
                // this.totalPage=res.data.page_info.total;
            }
        },
        pageChange(e){
			//翻页
			this.page=e;
			this.getCircleAdminList();
        },
        async deleteCircle(){
            //删除圈子类型
             let judge=null
            try {
              judge=  await this.$confirm('删除该圈子?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
                })
            } catch (error) {
                judge='cancel'
            }
            console.log(judge)
        },
        async submit(){
            //新增
            let params={
                name:this.name
            }
            let res=await this.$api.adminAddCircleClassify(params);
            if(res.data.level=='success'){
                this.$message({
                    type:'success',
                    message:res.data.message
                })
            }else{
                this.$message({
                    type:'error',
                    message:res.data.message
                })
                
            }
            
        },
        async getRoleList(page){
            //获取角色
            let params = {
                        limit:20,
                        page:page || 1,
                    }
            const res = await this.$api.getRoleList(params);
            if(res.data.level=='success'){
                this.roleList = res.data.data;
            }else{
                this.$message({
                message: res.data.message,
                type: 'error'
                });
            }
            },
        initData(){

        }

    },
    mounted() {
        this.id=this.$route.query.id;
        this.getRoleList()
        this.getCircleAdminList()
    },
}
</script>
<style lang="scss" scoped>
.screen{
          margin-top: -10px !important;
      }
    .action-bar{
			background-color: #f2f2f2;
			height: 60px;
			margin: 10px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding-left: 20px;
			.action-bar-input{
				width: 250px;
				margin-right: 14px;
      }
      .task-form-text{
				color: #666666;
			}
		}
		.el-table-style{
			width: 100%;
			border: 1px solid #f2f2f2;
		}
		.footer-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #f2f2f2;
			padding: 8px;
			margin: 10px 0px;
			box-sizing: border-box;
		}
		.dialog-footer{
			text-align: center;
		}
		.executorList{
			display: flex;
			flex-wrap: wrap;
			div{
				margin:10px;
				border:1px solid #eee;
				border-radius: 5px;
				padding:5px 10px;
			}
		}
</style>
